
function initComponent(search, editing, store) {
    // 1. autoSave 设为false
	editing.set("autoSave", false);
	// 2. 关闭事件后，将form设为可修改状态
	setEditingEnable(editing, true);
	
	// 点击确定时间重定义，查看状态不提交数据
	editing.on('accept', function(ev, form) {
    	var record = ev.record;
    	if (record.trigger_action && record.trigger_action === "view") {
    		editing.cancel();
    	} else {
    		//editing.set("autoSave", true);
    		//editing.saveRecord(record);
    		store.save(record);
    	}
    	if (form)
    		form.enable();
    	//editing.set("autoSave", false);
    	record.trigger_action = undefined;
    });
	
	// 关闭事件，置表单为可用状态
	var editor = editing.get('editor');
    editor.on('closed', function(e){
    	//alert(e.action);
    	var form = editing.get('form');
    	if (form)
    		editing.get('form').enable();
    });
    
    store.on("saved", function(obj){
   	 	var data = obj.data;
   	 	search.load();
   	 	if (data && data.success) {
   	 		BUI.Message.Alert('操作成功！', 'success');
   	 	} else {
   	 		BUI.Message.Alert(data.error, 'error');
   	 	}
    });
	
	//处理异常
    store.on('exception',function(ev){
      BUI.Message.Alert(ev.error);
    });
}

// 初始化editing组件，使其能适应增删改操作
function initEditing(editing) {
	// 1. autoSave 设为false
	editing.set("autoSave", false);
	// 2. 关闭事件后，将form设为可修改状态
	setEditingEnable(editing, true);
	
	// 点击确定时间重定义，查看状态不提交数据
	editing.on('accept', function(ev, form) {
    	var record = ev.record;
    	if (record.trigger_action && record.trigger_action === "view") {
    		editing.cancel();
    	} else {
    		editing.set("autoSave", true);
    		editing.saveRecord(record);
    	}
    	if (form)
    		form.enable();
    	editing.set("autoSave", false);
    	record.trigger_action = undefined;
    });
	
	// 关闭事件，置表单为可用状态
	var editor = editing.get('editor');
    editor.on('closed', function(e){
    	//alert(e.action);
    	var form = editing.get('form');
    	if (form)
    		editing.get('form').enable();
    });
}

// 设置bui editing对话框的可编辑性
function setEditingEnable(editing, enable) {
	var form = editing.get('form');
	if (enable)
		form.enable(); 
	else 
		form.disable();
}

// 初始化search的store保存后时间，弹窗提示操作结果
function initSearchStore(store) {
	store.on("saved", function(obj){
   	 	var data = obj.data;
   	 	if (data && data.success) {
   	 		BUI.Message.Alert('操作成功！', 'success');
   	 	} else {
   	 		BUI.Message.Alert(data.error, 'error');
   	 	}
    });
	
	//处理异常
    store.on('exception',function(ev){
      //BUI.Message.Alert(ev.error);
    });
}

//初始化search的store保存后时间，弹窗提示操作结果
function initSearchAndStore(search, store) {
	store.on("saved", function(obj){
   	 	var data = obj.data;
   	 	search.load();
   	 	if (data && data.success) {
   	 		BUI.Message.Alert('操作成功！', 'success');
   	 	} else {
   	 		BUI.Message.Alert(data.error, 'error');
   	 	}
    });
	
	//处理异常
    store.on('exception',function(ev){
      //BUI.Message.Alert(ev.error);
    });
}